package com.service.bean;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import com.service.bean.company.Company;
import com.service.bean.alarm.RoadAlarmRule;
import com.service.bean.device.Device;
import com.service.bean.device.Sensor;
import com.service.bean.oil.OilBox;

public class Road_Vehicle {
	
	public String equipmentId;
	
	public String equipmentNO;
	
	public String equipmentKind;
	
	public double totalMile;
	
	public double totalMile2;
	
	public String plateNO;
	
	public OilBox oilBox;
	
	public Device device;
	
	public Company company;

	public Map<String,Sensor> sensorMap = new HashMap<String,Sensor>();

	public Map<String,RoadAlarmRule> roadAlarmRuleMap = new HashMap<String,RoadAlarmRule>();
	public Map<String,RoadAlarmRule> mixingAlarmRuleMap = new HashMap<String,RoadAlarmRule>();
	/**
	 * 计算完油量、里程等变化量后的上一条数据
	 */
	public Road_GpsSignal lastGps;
	/**
	 * 上一条终端发送过来，经过初步解析后的数据(乱序，不按时间排序)
	 */
	public Road_GpsSignal lastGps_Received;
	/**
	 * 按时间排序后最新一条Gps信号
	 */
	public Road_GpsSignal lastGps_lastest;
	
	/**
	 * 车辆类型
	 */
	public String kindCode;
	/**
	 * 油量计算相关
	 */
	public LinkedList<Double> lastList;
	
	/**
	 * 更新最新时间的signal信号数据
	 */
	public void setLastGps_lastest(Road_GpsSignal signal){
		if (null == lastGps_lastest 
			|| lastGps_lastest.gpsTime.before(signal.gpsTime))
			lastGps_lastest = signal;
	}
	
	/**
	 * 前端E0命令获取最新时间的signal信号数据
	 */
	public Road_GpsSignal getLastGps_Received() {
		
		if(lastGps_lastest == null){
			return lastGps;
		}
		if(lastGps == null){
			return lastGps_Received;
		}
		
		if (lastGps.gpsTime.before(lastGps_lastest.gpsTime)){
			//历史数据的时间比缓存里的时间新，返回历史数据
			return lastGps_lastest;
		}else{
			return lastGps;
		}		
	}
}

